package com.koron.operation.classes.form.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.query.OrderItem;
import com.koron.bean.query.PageQuery;
import com.koron.operation.classes.form.bean.po.ClassesFormUser;
import com.koron.operation.classes.form.bean.query.ClassesFormUserQuery;
import com.koron.operation.classes.form.mapper.ClassesFormUserMapper;
import com.koron.operation.classes.form.service.ClassesFormUserService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 月度排班表人员配置(ClassesFormUser)表服务实现类
 *
 * @author jzp
 * @since 2023-07-18 17:50:58
 */
@Service
public class ClassesFormUserServiceImpl implements ClassesFormUserService {

    /**
     * 通过ID查询单条数据
     */
    @Override
    @TaskAnnotation("getById")
    public ClassesFormUser getById(SessionFactory factory, String id) {
        ClassesFormUserMapper mapper = factory.getMapper(ClassesFormUserMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     */
    @Override
    @TaskAnnotation("list")
    public List<ClassesFormUser> list(SessionFactory factory, ClassesFormUserQuery query) {
        ClassesFormUserMapper mapper = factory.getMapper(ClassesFormUserMapper.class);
        return mapper.selectList(query);
    }

    @Override
    @TaskAnnotation("page")
    public PageInfo<ClassesFormUser> page(SessionFactory factory, PageQuery pageQuery, ClassesFormUserQuery query) {
        pageQuery.setOrders(Collections.singletonList(new OrderItem("sort", true)));
        if (pageQuery.getPageNum() == 0) {
            PageHelper.orderBy(pageQuery.getOrderBy());
        } else {
            PageHelper.startPage(pageQuery);
        }
        List<ClassesFormUser> classesFormUserList = list(factory, query);
        return new PageInfo<>(classesFormUserList);
    }

    /**
     * 新增数据
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, ClassesFormUser classesFormUser) {
        ClassesFormUserMapper mapper = factory.getMapper(ClassesFormUserMapper.class);
        return mapper.insertOrUpdate(classesFormUser) > 0;
    }

    /**
     * 修改数据
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, ClassesFormUser classesFormUser) {
        ClassesFormUserMapper mapper = factory.getMapper(ClassesFormUserMapper.class);
        return mapper.update(classesFormUser) > 0;
    }

    /**
     * 通过主键删除数据
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        ClassesFormUserMapper mapper = factory.getMapper(ClassesFormUserMapper.class);
        return mapper.hidden(id) > 0;
    }
}
